/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StatGraphic.java
 *
 * Created on 2011-04-10, 19:42:18
 */

package panes;

import java.awt.Color;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.plaf.metal.MetalProgressBarUI;
import utils.StatGraphicData;

/**
 *
 * @author chocoseb
 */
public class StatGraphic extends javax.swing.JPanel {

    private ArrayList<StatGraphicData> _data = new ArrayList<StatGraphicData>();
    private int _max = 0;

    /** Creates new form StatGraphic */
    public StatGraphic() {
        initComponents();
    }

    public void addData(double p_value, String p_name, Color p_color){
        StatGraphicData data = new StatGraphicData(p_value, p_name, p_color);
        if (_max < p_value){
            _max = (int)Math.round(p_value);
        }
        _data.add(data);
    }

    public void createGraphic(){
//        int numberofColumn = _data.size();
//        int height =  this.getSize().height / numberofColumn;
//        int width = this.getSize().width - 100;
        for (StatGraphicData d : _data){
            JLabel lbl = new JLabel(d.getName() + " : ");
            this.add(lbl);
            JProgressBar prog = new JProgressBar(0,_max);
            prog.setUI(new MetalProgressBarUI());
            prog.setForeground(d.getColor());
            prog.setStringPainted(true);
            
            prog.setString(prog.getName());
            prog.setValue((int)Math.round(d.getValue()));
            prog.setSize(200, 30);
            prog.setBorder(BorderFactory.createLineBorder(Color.black));
            this.add(prog);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
